package com.sdry.web.controller.cb;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sdry.model.cb.OtherCostEntity;
import com.sdry.model.cb.TableDataInfo;
import com.sdry.model.lz.Warehouse;
import com.sdry.service.cb.OtherCostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("otherCost")
public class OtherCostController extends BaseController{

    @Autowired
    private OtherCostService otherCostService;

    @RequestMapping()
    public String index(Model model) {
        //仓库
        List<Warehouse> warehouseList = iDicMapper.getWarehouseList();
        model.addAttribute("warehouseList",warehouseList);
        return "cb/otherCost";
    }

    @RequestMapping("list")
    @ResponseBody
    public TableDataInfo getList(
            @RequestParam("page") Integer page ,
            @RequestParam("pageSize") Integer pageSize,
            String date,
            Long stockId
    ) {
        PageHelper.startPage(page,pageSize);
        List<OtherCostEntity> list = otherCostService.getList(date,stockId);
        PageInfo pageInfo = new PageInfo(list,5);
        return getDataTable(pageInfo.getList(),Math.toIntExact(pageInfo.getTotal()));
    }

    @RequestMapping("add")
    @ResponseBody
    public Integer add(OtherCostEntity otherCostEntity) {
        return otherCostService.add(otherCostEntity);
    }

    @RequestMapping("del")
    @ResponseBody
    public Integer del (@RequestParam("idArr[]") String[] idArr) {
        return otherCostService.delete(idArr);
    }
}
